package com.cx.controller.fhy;

import com.cx.pojo.Game;
import com.cx.pojo.ResultData;
import com.cx.service.fhy.GameService;
import com.cx.service.fhy.GamemallService;
import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("gamemall")
public class GamemallController {
    @Autowired
    private GamemallService gamemallService;

    @RequestMapping("selectall")
    @ResponseBody
    public List<Game> selectAll(HttpSession session) {
        List<Game> game = gamemallService.selectAll();
        return game;
    }


    @RequestMapping("selectgame")
    @ResponseBody
    public List<Game> selectGame(String gameName) {
        List<Game> game = gamemallService.selectByGameName(gameName);
        return game;
    }

    @RequestMapping("selectbytype")
    @ResponseBody
    public List<Game> selectByType(String gtId) {
        List<Game> game = gamemallService.selectByType(gtId);
        return game;
    }

    @RequestMapping("selectbydiscount")
    @ResponseBody
    public List<Game> selectByDiscount() {
        List<Game> game = gamemallService.selectByDiscount();
        return game;
    }

    @RequestMapping("selectbyprice")
    @ResponseBody
    public List<Game> selectByPrice(String gameLower,String gameHigher) {
        Map<String,Long> params = new HashMap<>();
        Long lower = null;
        Long higher = null;
        if(gameLower != null && gameLower != "") {
            lower = Long.parseLong(gameLower);
        }
        if(gameHigher != null && gameHigher != "") {
            higher = Long.parseLong(gameHigher);
        }

        params.put("lower",lower);
        params.put("higher",higher);

        List<Game> game = gamemallService.selectByPrice(params);
        return game;
    }
}